package com.leyantech.ecp.agenx.loadtest.di;

import com.leyantech.chaos.kafka.KafkaConsumerStringClient;
import com.leyantech.chaos.kafka.KafkaProducerStringClient;
import com.leyantech.ecp.agenx.loadtest.consumer.MessageConsumer;

import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Provides;
import com.google.inject.Singleton;

/**
 * @author eahau, {@literal <eahau@foxmail.com>}
 * @date 2022-11-18.
 */
public class LoadTestModule extends AbstractModule {

  @Override
  protected void configure() {

    bind(KafkaConsumerStringClient.class)
        .toProvider(loadtestConsumerProvider())
        .asEagerSingleton();

  }

  Provider<KafkaConsumerStringClient> loadtestConsumerProvider() {

    return new Provider<KafkaConsumerStringClient>() {

      @Inject
      MessageConsumer processor;

      @Override
      public KafkaConsumerStringClient get() {
        return KafkaConsumerStringClient.newBuilder("loadtest")
            .setProcessor(processor)
            .build();
      }
    };
  }

  @Singleton
  @Provides
  public KafkaProducerStringClient provideKafkaProducerStringClient() {
    return KafkaProducerStringClient.newBuilder("connector").build();
  }

}
